﻿using System;
using System.ComponentModel;
using System.Windows.Threading;
using Prism.Mvvm;

namespace Honest.MES.WPF.ViewModels
{
    public class StatusViewModel : BindableBase, IDisposable
    {
        private readonly DispatcherTimer _timer;
        private string _statusMessage = "就绪";
        private string _currentTime;

        public StatusViewModel()
        {
            UpdateTime();

            _timer = new DispatcherTimer(DispatcherPriority.Background)
            {
                Interval = TimeSpan.FromSeconds(1)
            };
            _timer.Tick += (s, e) => UpdateTime();
            _timer.Start();
        }

        public string StatusMessage
        {
            get => _statusMessage;
            set => SetProperty(ref _statusMessage, value);
        }

        public string CurrentTime
        {
            get => _currentTime;
            set => SetProperty(ref _currentTime, value);
        }

        private void UpdateTime()
        {
            CurrentTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }

        public void Dispose()
        {
            _timer?.Stop();
        }
    }
}